/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.ui.properties.advanced;

import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;

import com.cea.papyrus.core.ui.dialogs.LiteralIntegerDialog;
import com.cea.papyrus.core.ui.dialogs.UnlimitedNaturalDialog;
import com.cea.papyrus.core.ui.dialogs.ValueSpecificationDialog;
import com.cea.papyrus.core.utils.Debug;

/**
 * a new Font dialog cell editor.
 */
public class CreateValueCellEditor extends DialogCellEditor {
	
	/** Debug channel */
	protected final int channel = 21;
	
	/**
	 * 
	 */
	protected ValueSpecificationDialog cDialog;
	
	/**
	 * 
	 */
	protected Class dialog;
	
    /**
     * Creates a new Font dialog cell editor parented under the given control.
     * The cell editor value is <code>null</code> initially, and has no
     * validator.
     * 
     * @param dialog 
     * @param parent the parent control
     */
    protected CreateValueCellEditor(Composite parent,Class dialog) {
        super(parent);
        this.dialog=dialog;
    }

    /**
     * 
     * 
     * @param cellEditorWindow 
     * 
     * @return 
     * 
     * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(Control)
     */
    @Override
	protected Object openDialogBox(Control cellEditorWindow) {
    	if (dialog==LiteralIntegerDialog.class){
    	cDialog = new LiteralIntegerDialog(PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow().getShell());
    	}
    	else if (dialog==UnlimitedNaturalDialog.class){
        	cDialog = new UnlimitedNaturalDialog(PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow().getShell());
        	}
    	else{
    		Debug.error(this, "error: bad choose dialog at"+this.getClass()+":"+ dialog, channel);}

        cDialog.open();
        
        return getValue();
        //value;
    }
    
    /**
     * 
     * 
     * @return 
     */
    @Override
	protected Object doGetValue(){
    	// check if dialog is not null 
    	// it can happened when the dialog is not opened, area is just selected for example
    	if(cDialog!=null) {
    		return cDialog.getValue();
    	}
    	return null;
    }
    

}
